package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Books;
import com.example.demo.entity.Categories;
import com.example.demo.service.CategoriesService;
import com.example.demo.mapper.CategoriesMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author GJC
* @description 针对表【categories】的数据库操作Service实现
* @createDate 2025-01-12 23:14:37
*/
@Service
public class CategoriesServiceImpl extends ServiceImpl<CategoriesMapper, Categories>
    implements CategoriesService{
    //获取所有图书分类信息接口
    public List<Categories> getList(){
        return this.baseMapper.selectList(new QueryWrapper<>());
    }
    //接收分类信息并添加新分类
    public int addCategories(Categories categories){
        return this.baseMapper.insert(categories);
    }
    //根据分类ID更新分类信息
    public int updateCategories(Categories categories){
        QueryWrapper<Categories> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("id",categories.getId());
        return this.baseMapper.update(categories,queryWrapper);
    }
    //根据分类ID删除分类（需管理员权限）。
    public int delCategories(int id){
        return this.baseMapper.deleteById(id);
    }
}




